<?
namespace Api\View
{
	/** Layout class
	*/
	class	Layout	extends \Api\View
	{
		final public function	display($template=null){		
			if(!$template) $template = $this->m_config['Layout'];		
			
			$template = $this->m_config['LayoutDir'].'/'.$template;
			
			if(strlen($template) == 0 || !is_file($this->m_smarty->template_dir[0].'/'.$template))
				throw new \Exception('LAYOUT TEMPLATE FILE DOESN\'T EXISTS '.$this->m_smarty->template_dir[0].'/'.$template);
			
			$this->m_smarty->display($template);						
		}
		
        /** Changes layout file to specific template         
        */
        public function SetLayout($layout)
        {
            $this->m_config['Layout'] = $layout;
        }
        
	/** Layout template variable **/
		const LAYOUT_TITLE = 'LayoutTitle';		
		const LAYOUT_HEAD = 'LayoutHead';
			
	/** USEFULL AND COMMON FUNCTION TO MANAGE LAYOUT
	**/
		public function SetTitle($_val){            			
			$this->m_smarty->append(self::LAYOUT_TITLE, $_val);
		}		
		
		public function SetScript($file,$type){			
			$this->m_smarty->append(self::LAYOUT_HEAD, array($type,$file));						
		}
	}
}
?>